package testshop.tools;

import testshop.entity.Goods;
import testshop.page.GoodsPage;
import testshop.page.MainPage;

import java.util.Scanner;

public class ScannerChoice {


    /*获取输入的字符*/
    public  static String ScannerInfoString(){

        Scanner scan =  new Scanner(System.in);
        System.out.println("请输入： ");
        return  scan.next();

    }


        /**
             *  java类简单作用描述
             * @ProjectName:
             * @Package:        testshop.tools
             * @ClassName:      ScannerChoice
             * @Description:     获得Double类型的输入
             * @Author:         zhoucan
             * @CreateDate:     2018/3/15 17:40
             * @UpdateUser:     作者姓名
             * @UpdateDate:     2018/3/15 17:40
             * @UpdateRemark:   The modified content
             * @Version:        1.0
             * </code>
             Copyright: Copyright (c) 2018/3/15
             * */
    public static double ScannerInfo(){

        double num = 0.00;
        do {
            Scanner sc = new Scanner(System.in);
            System.out.println("保留后面两位小数，请输入");
            String info = sc.next();


            String regex = "(([1-9][0-9]*)\\.([0-9]{2}))|([0]\\.[0-9]{2})";

            if (info.matches(regex)){

                num = Double.parseDouble(info);

            }else{

                System.out.println("!输入错误，请按照要求输入");
                continue;


            }

            break;



        }while (true);

        return  num;

    }

      /**
           * 方法实现说明
           * @method      获得int类型的输入
           * @author      CanZhou
           * @version     1.0
           * @see         对类、属性、方法的说明 参考转向
            * @param null
           * @return
           * @exception
           * @date        2018/3/15 17:39
           */

    public static int ScannerNum()
    {
        int num = 0;
        String regex = "([1-9])|([1-9][0-9]+)";//商品数量
        do
        {
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入：");
            String nums = sc.next();

            if (nums.matches(regex))
            {
                num = Integer.parseInt(nums);
            }else
            {
                System.err.println("！输入有误！");
                continue;
            }
            break;
        } while (true);
        return num;
    }


    public  static  void  changeInfoNext(String info)
    {

        do {

            System.out.println("是否继续当前操作:(输入Y/N)");

            String choice = ScannerChoice.ScannerInfoString();

            if ("y".equals(choice.toLowerCase())){


                if (info.equals("updateGoodsPage")){

                    GoodsPage.updateGoodsPage();
                }else if (info.equals("deleteGoodsPage")){

                    GoodsPage.deleteGoodsPage();


                }else if (info.equals("addGoodsPage")){

                    GoodsPage.addGoodsPage();

                }


            }else if ("n".equals(choice.toLowerCase())){


                MainPage.goProductMaintenancePage();

            }

            System.out.println("输入错误！！！ 请输入Y或者N,不区分大小写");

        }while (true);













    }








}
